#include "DictServer.hpp"
#include "Dictionary.hpp"
#include <memory>

void Usage(std::string proc)//使用手册
{
    std::cout << "Usage: " << proc << " serverip serverport" << std::endl;
}

// std::string Translate(const std::string &word, const std::string &whoip, uint16_t whoport)
// {
//     return "haha";
// }

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(1);
    }

    uint16_t port = std::stoi(argv[1]);
    
    Console();
    Dictionary dict("./dict.txt");
    std::unique_ptr<DictServer> us = std::make_unique<DictServer>(port, 
        [&dict](const std::string &word, const std::string &whoip, uint16_t whoport)->std::string
        {
            return dict.Translate(word, whoip, whoport);
        }
    );
    us->Init();
    us->Start();
    return 0;
}